home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / enscript.4 / enscript / enscript-1.4.0 / src / gsint.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-17  |  12.3 KB  |  561 lines

  1. /* 
  2.  * Internal header file.
  3.  * Copyright (c) 1995 Markku Rossi.
  4.  *
  5.  * Author: Markku Rossi <mtr@iki.fi>
  6.  */
  7.  
  8. /*
  9.  * This file is part of GNU enscript.
  10.  * 
  11.  * This program is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2, or (at your option)
  14.  * any later version.
  15.  *
  16.  * This program is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with this program; see the file COPYING.  If not, write to
  23.  * the Free Software Foundation, 59 Temple Place - Suite 330,
  24.  * Boston, MA 02111-1307, USA.
  25.  */
  26.  
  27. #ifndef GSINT_H
  28. #define GSINT_H
  29.  
  30. /*
  31.  * Config stuffs.
  32.  */
  33.  
  34. #ifdef HAVE_CONFIG_H
  35. #include <config.h>
  36. #endif
  37.  
  38. #include <stdio.h>
  39.  
  40. #ifndef __P
  41. #if PROTOTYPES
  42. #define __P(protos) protos
  43. #else /* no PROTOTYPES */
  44. #define __P(protos) ()
  45. #endif /* no PROTOTYPES */
  46. #endif
  47.  
  48. #if STDC_HEADERS
  49.  
  50. #include <stdlib.h>
  51. #include <string.h>
  52. #include <stdarg.h>
  53.  
  54. #else /* no STDC_HEADERS */
  55.  
  56. #if HAVE_STDLIB_H
  57. #include <stdlib.h>
  58. #endif
  59.  
  60. #if HAVE_STRING_H
  61. #include <string.h>
  62. #endif
  63.  
  64. #ifndef HAVE_STRCHR
  65. #define strchr index
  66. #define strrchr rindex
  67. #endif
  68. char *strchr ();
  69. char *strrchr ();
  70.  
  71. #ifndef HAVE_MEMCPY
  72. #define memcpy(d, s, n) bcopy((s), (d), (n))
  73. #define memmove(d, s, n) bcopy((s), (d), (n))
  74. #endif
  75.  
  76. #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
  77. #include <stdarg.h>
  78. #else
  79. #include <varargs.h>
  80. #endif
  81.  
  82. #ifndef HAVE_STRERROR
  83. extern char *strerror __P ((int));
  84. #endif
  85.  
  86. #endif /* no STDC_HEADERS */
  87.  
  88. #if HAVE_UNISTD_H
  89. #include <unistd.h>
  90. #endif
  91.  
  92. #if HAVE_MATH_H
  93. #include <math.h>
  94. #else
  95. extern double atan2 __P ((double, double));
  96. #endif
  97.  
  98. #include <errno.h>
  99. #include <time.h>
  100. #include <assert.h>
  101. #include <sys/types.h>
  102. #include <ctype.h>
  103. #include <sys/stat.h>
  104.  
  105. #if HAVE_PWD_H
  106. #include <pwd.h>
  107. #else
  108. #include "dummypwd.h"
  109. #endif
  110.  
  111. #if ENABLE_NLS
  112. #include <libintl.h>
  113. #define _(String) gettext (String)
  114. #else
  115. #define _(String) String
  116. #endif
  117.  
  118. #if HAVE_LC_MESSAGES
  119. #include <locale.h>
  120. #endif
  121.  
  122. #ifndef HAVE_GETCWD
  123. #if HAVE_GETWD
  124. #define getcwd(buf, len) getwd(buf)
  125. #endif /* HAVE_GETWD */
  126. #endif /* not HAVE_GETCWD */
  127.  
  128. #include "afm.h"
  129. #include "strhash.h"
  130.  
  131. /* 
  132.  * Types and definitions.
  133.  */
  134.  
  135. #define MATCH(a, b) (strcmp (a, b) == 0)
  136.  
  137. #define ISNUMBERDIGIT(ch) \
  138.   (('0' <= (ch) && (ch) <= '9') || (ch) == '.' || (ch) == '-' || (ch) == '+')
  139.  
  140. /* Return the width of the character <ch> */
  141. #define CHAR_WIDTH(ch) (font_widths[(unsigned char) (ch)])
  142.  
  143. /* Current point y movement from line to line. */
  144. #define LINESKIP (Fpt + baselineskip)
  145.  
  146.  
  147. /* Constants for output files. */
  148. #define OUTPUT_FILE_NONE   NULL
  149. #define OUTPUT_FILE_STDOUT ((char *) 1)
  150.  
  151. /* Underlay styles. */
  152. #define UL_STYLE_OUTLINE     0
  153. #define UL_STYLE_FILLED        1
  154.  
  155. struct media_entry_st
  156. {
  157.   struct media_entry_st *next;
  158.   char *name;
  159.   int w;
  160.   int h;
  161.   int llx;
  162.   int lly;
  163.   int urx;
  164.   int ury;
  165. };
  166.  
  167. typedef struct media_entry_st MediaEntry;
  168.  
  169. typedef enum
  170. {
  171.   HDR_NONE,
  172.   HDR_SIMPLE,
  173.   HDR_FANCY
  174. } HeaderType;
  175.  
  176.  
  177. typedef enum
  178. {
  179.   ENC_LATIN1,
  180.   ENC_LATIN2,
  181.   ENC_LATIN3,
  182.   ENC_ASCII,
  183.   ENC_ASCII_SCANDS,
  184.   ENC_IBMPC,
  185.   ENC_MAC,
  186.   ENC_VMS,
  187.   ENC_HP8,
  188.   ENC_PS
  189. } InputEncoding;
  190.  
  191. typedef enum
  192. {
  193.   LABEL_SHORT,
  194.   LABEL_LONG
  195. } PageLabelFormat;
  196.  
  197. typedef enum
  198. {
  199.   NPF_SPACE,
  200.   NPF_QUESTIONMARK,
  201.   NPF_CARET,
  202.   NPF_OCTAL
  203. } NonPrintableFormat;
  204.  
  205. typedef enum
  206. {
  207.   FORMFEED_COLUMN,
  208.   FORMFEED_PAGE
  209. } FormFeedType;
  210.  
  211. struct file_lookup_ctx_st
  212. {
  213.   char name[256];
  214.   char suffix[256];
  215.   char fullname[512];
  216. };
  217.  
  218. typedef struct file_lookup_ctx_st FileLookupCtx;
  219.  
  220. typedef int (*PathWalkProc) __P ((char *path, void *context));
  221.  
  222. struct input_stream_st
  223. {
  224.   int is_pipe;            /* Is <fp> opened to pipe? */
  225.   FILE *fp;
  226.   unsigned char buf[4096];
  227.   unsigned int data_in_buf;
  228.   unsigned int bufpos;
  229.   unsigned int nreads;
  230.   int unget_ch;
  231. };
  232.  
  233. typedef struct input_stream_st InputStream;
  234.  
  235. struct page_range_st
  236. {
  237.   struct page_range_st *next;
  238.   int odd;
  239.   int even;
  240.   unsigned int start;
  241.   unsigned int end;
  242. };
  243.  
  244. typedef struct page_range_st PageRange;
  245.  
  246.  
  247. /* 
  248.  * Global variables.
  249.  */
  250.  
  251. extern char *program;
  252. extern FILE *ofp;
  253. extern char version_string[];
  254. extern char ps_version_string[];
  255. extern char date_string[];
  256. extern struct tm run_tm;
  257. extern struct tm mod_tm;
  258. extern struct passwd *passwd;
  259. extern char libpath[];
  260. extern char *afm_path;
  261. extern char afm_path_buffer[];
  262. extern MediaEntry *media_names;
  263. extern MediaEntry *media;
  264. extern char spooler_command[];
  265. extern char queue_param[];
  266. extern int nl;
  267. extern int bs;
  268. extern unsigned int current_pagenum;
  269.  
  270. /* Statistics. */
  271. extern int total_pages;
  272. extern int num_truncated_lines;
  273. extern int num_missing_chars;
  274. extern int missing_chars[];
  275. extern int num_non_printable_chars;
  276. extern int non_printable_chars[];
  277.  
  278. /* Dimensions that are used during PostScript generation. */
  279. extern int d_page_w;
  280. extern int d_page_h;
  281. extern int d_header_w;
  282. extern int d_header_h;
  283. extern int d_footer_h;
  284. extern int d_output_w;
  285. extern int d_output_h;
  286. extern int d_output_x_margin;
  287. extern int d_output_y_margin;
  288.  
  289. /* Document needed resources. */
  290. extern StringHashPtr res_fonts;
  291.  
  292. /* Fonts to download. */
  293. extern StringHashPtr download_fonts;
  294.  
  295. /* Additional key-value pairs, passed to the generated PostScript code. */
  296. extern StringHashPtr pagedevice;
  297. extern StringHashPtr statusdict;
  298.  
  299. /* User defined strings. */
  300. extern StringHashPtr user_strings;
  301.  
  302. /* Cache for AFM files. */
  303. extern StringHashPtr afm_cache;
  304.  
  305. /* AFM library handle. */
  306. extern AFMHandle afm;
  307.  
  308. /* Fonts. */
  309. extern char *HFname;
  310. extern double HFpt;
  311. extern char *Fname;
  312. extern double Fpt;
  313. extern double default_Fpt;
  314. extern char *default_Fname;
  315.  
  316. extern double font_widths[];
  317. extern char font_ctype[];
  318. extern int font_is_fixed;
  319. extern double font_bbox_lly;
  320.  
  321. /* Options. */
  322.  
  323. extern char *printer;
  324. extern char printer_buf[];
  325. extern int verbose;
  326. extern int num_copies;
  327. extern char *title;
  328. extern int num_columns;
  329. extern int truncate_lines;
  330. extern int quiet;
  331. extern int landscape;
  332. extern HeaderType header;
  333. extern char *fancy_header_name;
  334. extern char fancy_header_default[];
  335. extern double line_indent;
  336. extern char *page_header;
  337. extern char *output_file;
  338. extern unsigned int lines_per_page;
  339. extern InputEncoding encoding;
  340. extern char *media_name;
  341. extern char media_name_buffer[];
  342. extern char *encoding_name;
  343. extern char encoding_name_buffer[];
  344. extern int special_escapes;
  345. extern int escape_char;
  346. extern int tabsize;
  347. extern double baselineskip;
  348. extern double ul_ptsize;
  349. extern double ul_gray;
  350. extern char *ul_font;
  351. extern char *underlay;
  352. extern char ul_position_buf[];
  353. extern char *ul_position;
  354. extern double ul_x;
  355. extern double ul_y;
  356. extern double ul_angle;
  357. extern unsigned int ul_style;
  358. extern char *ul_style_str;
  359. extern char ul_style_str_buf[];
  360. extern int ul_position_p;
  361. extern int ul_angle_p;
  362. extern PageLabelFormat page_label;
  363. extern char *page_label_format;
  364. extern char page_label_format_buf[];
  365. extern int pass_through;
  366. extern int line_numbers;
  367. extern int interpret_formfeed;
  368. extern NonPrintableFormat non_printable_format;
  369. extern char *npf_name;
  370. extern char npf_name_buf[];
  371. extern int clean_7bit;
  372. extern int append_ctrl_D;
  373. extern unsigned int highlight_bars;
  374. extern double highlight_bar_gray;
  375. extern int page_prefeed;
  376. extern PageRange *page_ranges;
  377. extern int borders;
  378. extern double line_highlight_gray;
  379. extern int accept_composites;
  380. extern FormFeedType formfeed_type;
  381. extern char *input_filter_stdin;
  382.  
  383.  
  384. /* 
  385.  * Prototypes for global functions.
  386.  */
  387.  
  388. /* Print message if <verbose> is >= <verbose_level>. */
  389. void message __P ((int verbose_level, char *fmt, ...));
  390.  
  391. /* Report continuable error. */
  392. void error __P ((char *fmt, ...));
  393.  
  394. /* Report fatal error and exit with status 1.  Function never returns. */
  395. void fatal __P ((char *fmt, ...));
  396.  
  397. /* 
  398.  * Read config file <path, name>.  Returns bool.  If function fails, error
  399.  * is found from errno.
  400.  */
  401. int read_config __P ((char *path, char *name));
  402.  
  403. /* Print PostScript header to our output stream. */
  404. void dump_ps_header __P ((void));
  405.  
  406. /* Print PostScript trailer to our output stream. */
  407. void dump_ps_trailer __P ((void));
  408.  
  409. /*
  410.  * Open InputStream to <fp> or <fname>.  If <input_filter> is given
  411.  * it is used to pre-filter the incoming data stream.  Function returns
  412.  * 1 if stream could be opened or 0 otherwise.
  413.  */
  414. int is_open __P ((InputStream *is, FILE *fp, char *fname,
  415.           char *input_filter));
  416.  
  417. /* Close InputStream <is>. */
  418. void is_close __P ((InputStream *is));
  419.  
  420. /*
  421.  * Read next character from the InputStream <is>.  Returns EOF if 
  422.  * EOF was reached.
  423.  */
  424. int is_getc __P ((InputStream *is));
  425.  
  426. /*
  427.  * Put character <ch> back to the InputStream <is>.  Function returns EOF
  428.  * if character couldn't be unget.
  429.  */
  430. int is_ungetc __P ((int ch, InputStream *is));
  431.  
  432. /* 
  433.  * Process single input file <fp>.  File's name is given in <fname> and
  434.  * it is used to print headers.
  435.  */
  436. void process_file __P ((char *fname, InputStream *fp));
  437.  
  438. /* Add a new media to the list of known media. */
  439. void add_media __P ((char *name, int w, int h, int llx, int lly, int urx,
  440.              int ury));
  441.  
  442. /* Print a listing of missing characters. */
  443. void do_list_missing_characters __P ((int *array));
  444.  
  445. /* 
  446.  * Check if file <name, suffix> exists.  Returns bool.  If function fails
  447.  * error can be found from errno.
  448.  */
  449. int file_existsp __P ((char *name, char *suffix));
  450.  
  451. /*
  452.  * Paste file <name, suffix> to output stream.  Returns bool. If 
  453.  * function fails, error can be found from errno.
  454.  */
  455. int paste_file __P ((char *name, char *suffix));
  456.  
  457. /*
  458.  * Do tilde substitution for filename <from> and insert result to <to>.
  459.  * Buffer <to> must be long enought to hold expanded name.
  460.  */
  461. void tilde_subst __P ((char *from, char *to));
  462.  
  463. /*
  464.  * Parse one float dimension from string <string>.  If <units> is true,
  465.  * then number can be followed by an optional unit specifier.  If
  466.  * <horizontal> is true, then dimension is horizontal, otherwise it
  467.  * is vertical.
  468.  */
  469. double parse_float __P ((char *string, int units, int horizontal));
  470.  
  471. /*
  472.  * Parse font spec <spec> and return font's name and size in variables
  473.  * <name_return> and <size_return>.  Returns 1 if <spec> was a valid
  474.  * font spec or 0 otherwise.  Returned name <name_return> is allocated
  475.  * with xcalloc() and must be freed by caller.
  476.  */
  477. int parse_font_spec __P ((char *spec, char **name_return,
  478.               double *size_return));
  479.  
  480. /*
  481.  * Read body font's character widths and character codes from AFM files.
  482.  */
  483. void read_font_info __P ((void));
  484.  
  485. /*
  486.  * Try to download font <name>.
  487.  */
  488. void download_font __P ((char *name));
  489.  
  490. /*
  491.  * Escape all PostScript string's special characters from string <string>.
  492.  * Returns a xmalloc()ated result.
  493.  */
  494. char *escape_string __P ((char *string));
  495.  
  496. /*
  497.  * Expand user escapes from string <string>.  Returns a xmalloc()ated
  498.  * result.
  499.  */
  500. char *format_user_string __P ((char *string));
  501.  
  502. /*
  503.  * Parses key-value pair <kv> and inserts/deletes key from <set>.
  504.  */
  505. void parse_key_value_pair __P ((StringHashPtr set, char *kv));
  506.  
  507. /*
  508.  * Count how many non-empty items there are in the key-value set <set>.
  509.  */
  510. int count_key_value_set __P ((StringHashPtr set));
  511.  
  512. /*
  513.  * Walk through path <path> and call <proc> once for each of its
  514.  * components.  Function returns 0 if all components were accessed.
  515.  * Callback <proc> can interrupt walking by returning a non zero
  516.  * return value.  In that case value is returned as the return value
  517.  * of the pathwalk().
  518.  */
  519. int pathwalk __P ((char *path, PathWalkProc proc, void *context));
  520.  
  521. /* Lookup file from path.  <context> must point to FileLookupCtx. */
  522. int file_lookup __P ((char *path, void *context));
  523.  
  524.  
  525. /* 
  526.  * Non-failing memory allocation.
  527.  */
  528.  
  529. void *xmalloc __P ((size_t size));
  530.  
  531. void *xcalloc __P ((size_t num, size_t size));
  532.  
  533. void *xrealloc __P ((void *ptr, size_t size));
  534.  
  535. void xfree __P ((void *ptr));
  536.  
  537. char *xstrdup __P ((char *));
  538.  
  539.  
  540. /*
  541.  * Portable printer interface.
  542.  */
  543.  
  544. /*
  545.  * Open and initialize printer <cmd>, <options>, <queue_param> and
  546.  * <printer_name>.  Function returns a FILE pointer to which enscript
  547.  * can generate its PostScript output or NULL if printer
  548.  * initialization failed.  Command can store its context information
  549.  * to variable <context_return> wich is passed as an argument to the
  550.  * printer_close() function.
  551.  */
  552. FILE *printer_open __P ((char *cmd, char *options, char *queue_param,
  553.              char *printer_name, void **context_return));
  554.  
  555. /*
  556.  * Flush all pending output to printer <context> and close it.
  557.  */
  558. void printer_close __P ((void *context));
  559.  
  560. #endif /* not GSINT_H */
  561.